<%@page import="helpers.LanguageHelper"%>
<%@page import="helpers.UrlHelper"%>
<%@page import="helpers.DateHelper"%>
<%@page import="entities.Category"%>
<%@page import="entities.User"%>
<%@page import="java.util.Map"%>
<%@page import="helpers.PaginatorHelper"%>
<%@page import="helpers.StringHelper"%>
<%@page import="entities.Article"%>
<%@page import="java.util.List"%>
<%
User author = (User) request.getAttribute("author");
List<Article> articles = (List<Article>) request.getAttribute("articles"); 
Map<String, Category> categories = (Map<String, Category>) request.getAttribute("categories");
Category category = null;
LanguageHelper translate = (LanguageHelper) request.getAttribute("translate");
String success = (String) request.getAttribute("success");

//Paginator
int pages = (Integer) request.getAttribute("page");
boolean nextPage = (Boolean) request.getAttribute("nextPage");
boolean prevPage = (Boolean) request.getAttribute("prevPage");
PaginatorHelper paginator = (PaginatorHelper) request.getAttribute("paginator");
%>

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<jsp:include page="/user/layouts/header.jsp" />
<script type="text/javascript">
jQuery(document).ready(function () {
	jQuery(".remove").click(function () {
		var answer=confirm("Are you realy delete this artclie?");
		if(answer) {
			return true;
		}
		return false;
	});
});
</script>
               
               
               
            <ul class="nav nav-tabs">
                <li>
                    <a href="/profile"><i class="icon-tasks"></i> Profile</a>
                </li>
                <li>
                    <a href="/profile/change-avatar"><i class="icon-user"></i> Change Avatar</a>
                </li>
                <li class="active">
                    <a href="/profile/article/list"><i class="icon-briefcase"></i> My Articles</a>
                </li>
                <li>
                    <a href="/profile/article/submit"><i class="icon-envelope"></i> Submit Article</a>
                </li>
            </ul>
            <div class="tab-content">
            	<div id="article-list-tab" class="tab-pane row-fluid active fade in">
                   	<% if (success != null) { %>
		            <div class="alert alert-success"><%=success %></div>
		            <% } %>
                   
                       <table cellpadding="0" cellspacing="0" width="100%" class="table table-hover">
                       	<thead>
                           	<tr>
                               	<th>#</th>
                                   <th width="45%">Title</th>
                                   <th>Status</th>
                                   <th>Created</th>
                                   <th>&nbsp;</th>
                               </tr>
                           </thead>
                           <tbody>
                           	<% 
			                for (int i = 0; i < articles.size(); i++) {
			                	category = categories.get(articles.get(i).getCategory());
			                %>
                           	<tr>
                               	<td><%=i+1 %></td>
                                   <td><h5><a href="/a/<%=articles.get(i).getAlias() %>"><%=articles.get(i).getTitle() %></a></h5></td>
                                   <td>
                                   	<%
                                   	switch (articles.get(i).getStatus()) {
                                   		case 0:
                                   			%>Unpublish<%
                                   			break;
                                   		case 1:
                                   			%>Published<%
                                   			break;
                                   		case 2:
                                   			%>Reviewing<%
                                   			break;
                                   	}
                                   	%>
                                   </td>
                                   <td><%=DateHelper.getStringFromDate(articles.get(i).getCreated(), "dd-MM-yyyy")  %></td>
                                   <td>
                                   	<div class="portfolio-links">
                                           <a href="/article/<%=articles.get(i).getAlias() %>" class="" target="_blank"><i class="icon-eye-open"></i> View</a>
                                           <a href="/profile/article/delete/<%=articles.get(i).getId() %>/<%=articles.get(i).getAuthKey() %>" class="remove"><i class="icon-remove"></i> Remove</a>
                                           <a href="/profile/article/edit/<%=articles.get(i).getId() %>/<%=articles.get(i).getAuthKey() %>" class=""><i class="icon-edit"></i> Edit</a>
                                       </div>
                                   </td>
                               </tr>
                               <% } %>
                           </tbody>
                       </table>
                       
                       <div class="pagination pagination-right">
                        <ul>
		                    <%
							List<Integer> range = paginator.getRangePage();
							%>
		                    <% if (prevPage) { %>
							<li><a href="<%=paginator.getPrev()%>"><%=translate.getString("prev")%></a></li>
							<% } %>
							<%
							if (nextPage || prevPage) {
								for (int i = 0; i < range.size(); i++) {
							%>
							<li><a class="<%=range.get(i).intValue() == pages ? "current" : "" %>" href="<%=range.get(i).intValue() == pages ? "javascript: return false;" : paginator.getPage(range.get(i).intValue())%>"> <%=range.get(i).toString() %> </a></li>
							<%  }
							} %>
							
							<% if (nextPage) { %>
							<li><a href="<%=paginator.getNext()%>"> <%=translate.getString("next")%> </a></li>
							<% } %>
		                </ul>
		            </div>
                </div>
            </div>
       
                    
<jsp:include page="/user/layouts/footer.jsp" />